# 作者：陈睿-cruise
# 2025年02月20日16时35分12秒
# 2979386061@qq.com
from pyecharts.charts import Line, Bar, Pie, Map
from pyecharts import options as opts
from pyecharts.charts import Grid

# 1. 折线图
line = Line()
line.add_xaxis(["Jan", "Feb", "Mar", "Apr", "May"])
line.add_yaxis("销售额", [5, 20, 36, 10, 75])
line.set_global_opts(title_opts=opts.TitleOpts(title="折线图示例"))

# 2. 柱状图
bar = Bar()
bar.add_xaxis(["A", "B", "C", "D"])
bar.add_yaxis("销售额", [23, 34, 45, 56])
bar.set_global_opts(title_opts=opts.TitleOpts(title="柱状图示例"))

# 3. 饼图
pie = Pie()
pie.add("分布", [("A", 40), ("B", 30), ("C", 20), ("D", 10)])
pie.set_global_opts(title_opts=opts.TitleOpts(title="饼图示例"))

# 4. 地图图表（中国地图示例）
map_chart = Map()
map_chart.add("销售额", [("北京", 100), ("上海", 200), ("广东", 300)], maptype="china")
map_chart.set_global_opts(title_opts=opts.TitleOpts(title="中国地图示例"))

# 5. 组合图（柱状图 + 折线图）使用 Grid
grid = Grid()

# 为每个图表单独设置配置，并添加到 Grid
grid.add(bar, grid_opts=opts.GridOpts(pos_left="55%"))
grid.add(line, grid_opts=opts.GridOpts(pos_right="55%"))

# 渲染图表
line.render("line_chart.html")
bar.render("bar_chart.html")
pie.render("pie_chart.html")
map_chart.render("map_chart.html")
grid.render("combo_chart.html")
